import http from '@/utils/http'

const BASE_URL = '/asset/device/records'

export interface DeviceLendResp {
  id: string
  deviceId: string
  userId: string
  lendTime: string
  lendDescription: string
  planTime: string
  returnTime: string
  returnDescription: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
  disabled: boolean
}

export interface DeviceRecordsResp {
  name: string
  code: string
  qrCodeUrl: string
  categoryId: string
  brand: string
  model: string
  deptId: string
  userId: string
  purchaseDate: string
  status: string
  isDel: string
  expireDate: string
  depreciationRuleId: string
  sn: string
  producerId: string
  price: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
  disabled: boolean
}

export interface DeviceRecordsDetailResp {
  id: string
  name: string
  code: string
  qrCodeUrl: string
  categoryId: string
  brand: string
  model: string
  deptId: string
  userId: string
  purchaseDate: string
  status: string
  isDel: string
  expireDate: string
  depreciationRuleId: string
  sn: string
  producerId: string
  price: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}

export interface DeviceRecordsQuery {
  fuzzy: string | undefined
  name: string | undefined
  code: string | undefined
  categoryId: string | undefined
  brand: string | undefined
  model: string | undefined
  deptId: string | undefined
  userId: string | undefined
  status: string | undefined
  isDel: string | undefined
  sn: string | undefined
  sort: Array<string>
}

export interface DeviceTracksResp {
  id: string
  deviceId: string
  carryName: string
  content: string
  createUser: string
  createTime: string
  createUserString: string
  updateUserString: string
  disabled: boolean
}

export interface DeviceRecordsPageQuery extends DeviceRecordsQuery, PageQuery { }

/** @desc 查询设备清单列表 */
export function listDeviceRecords(query: DeviceRecordsPageQuery) {
  return http.get<PageRes<DeviceRecordsResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询设备详情 */
export function getDeviceRecords(id: string) {
  return http.get<DeviceRecordsDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 查询设备履历 */
export function getDeviceTracks(id: string) {
  return http.get<DeviceTracksResp>(`${BASE_URL}/tracks/${id}`)
}

/** @desc 新增设备清单 */
export function addDeviceRecords(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改设备清单 */
export function updateDeviceRecords(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除设备清单 */
export function deleteDeviceRecords(id: string) {
  return http.del(BASE_URL, { ids: [id] })
}

/** @desc 撤销删除设备清单 */
export function deleteReturnDeviceRecords(id: string) {
  return http.get(`${BASE_URL}/delete/return/${id}`)
}

/** @desc 导出设备清单 */
export function exportDeviceRecords(query: DeviceRecordsQuery) {
  return http.download(`${BASE_URL}/export`, query)
}

/** @desc 查询设备回收站列表 */
export function listDeviceReycle(query: DeviceRecordsPageQuery) {
  return http.get<PageRes<DeviceRecordsResp[]>>(`${BASE_URL}/recycle/list`, query)
}

/** @desc 分配用户 */
export function deviceUse(data: any) {
  return http.post(`${BASE_URL}/use`, data)
}

/** @desc 设备借用 */
export function deviceLend(data: any) {
  return http.post(`${BASE_URL}/lend`, data)
}

/** @desc 设备归还 */
export function deviceReturn(data: any) {
  return http.post(`${BASE_URL}/return`, data)
}

/** @desc 设备报废 */
export function deviceDiscard(data: any) {
  return http.post(`${BASE_URL}/discard`, data)
}

/** @desc 撤销报废 */
export function deviceDiscardCancel(data: any) {
  return http.post(`${BASE_URL}/discard/cancel`, data)
}